The IMSL_SP_GMRES function solves a linear system Ax = b using the restarted generalized minimum residual (GMRES) method.
Note: This routine requires an IDL Analyst license. For more information, contact your Exelis sales or technical support representative.
This example finds the solution to a linear system.
The coefficient matrix is stored in coordinate format. Consider the following matrix: Let xT = (1, 2, 3, 4, 5, 6) so that Ax = (10, 7, 45, 33, –34, 31)T. The number of nonzeros in A is 15.
FUNCTION Amultp, p
; This function uses IMSL_SP_MVMUL to multiply a sparse
; matrix stored in coordinate storage mode and a vector.
; The common block holds the sparse matrix.
COMMON Gmres_ex1, nrows, ncols, a
RETURN, IMSL_SP_MVMUL(nrows, ncols, a, p)
END
PRO Gmres1
; This procedure defines the sparse matrix A stored in coordinate
; storage mode, and then calls IMSL_SP_GMRES to compute the
; solution to Ax = b.
COMMON Gmres_ex1, nrows, ncols, a
; Initialize sparse matrix structure variables
@imsl_init
A = REPLICATE(imsl_f_sp_elem, 15)
a(*).row = [0, 1, 1, 1, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5]
a(*).col = [0, 1, 2, 3, 2, 0, 3, 4, 0, 3, 4, 5, 0, 1, 5]
a(*).val = [10, 10, -3, -1, 15, -2, 10, -1, -1, -5, $
1, -3, -1, -2, 6]
nrows = 6
ncols = 6
b = [10, 7, 45, 33, -34, 31]
itmax = 10
; Itmax is input/output.
x = IMSL_SP_GMRES('amultp', b, Itmax = itmax)
pm, x, title = 'Solution to Ax = b'
pm, itmax, title = 'Number of iterations'
END
; Output of this procedure:
Solution to Ax = b
1.0000000
2.0000000
3.0000000
4.0000000
5.0000000
6.0000000
Number of iterations
6
Result = IMSL_SP_GMRES(amultp, b [, /DOUBLE] [, HH_REORTH=value] [, ITMAX=value] [, MAX_KRYLOV=value] [, PRECOND=value] [, TOLERANCE=value])
A one-dimensional array containing the solution of the linear system Ax = b.
Scalar string specifying a user supplied function that computes z = Ap. The function accepts the argument p, and returns the vector Ap.
One-dimensional matrix containing the right-hand side.
If present and nonzero, double precision is used.
If present and nonzero, perform orthogonalization by Householder transformations, replacing the Gram-Schmidt process.
Initially set to the maximum number of GMRES iterations allowed. On exit, the number of iterations used is returned. Default: ITMAX = 1000
The maximum Krylov subspace dimension, that is, the maximum allowable number of GMRES iterations allowed before restarting. Default: MAX_KRYLOV = Minimum(N_ELEMENTS(b), 20).
Scalar sting specifying a user supplied function which sets z = M–1r, where M is the preconditioning matrix.
The algorithm attempts to generate x such that: where t = TOLERANCE. Default: TOLERANCE = SQRT(machine precision).
|
6.4 |
Introduced |